Is there any way to know if I've done git push?

5

Whenever I need to update repositories, I use the git push command.

The problem is that sometimes I do not know if I've pulled or not, because I'm doing several things at the same time. From there to find out whether I made git push or not, I run git push again. But I would like a more efficient way of knowing if I already gave git push to the commits I just made, without having to do it all the time (after all, I have to be typing user and password).

Is there any quicker way to know if I've already done push of changes by Git ? Something like git status ?

    
asked by anonymous 23.06.2016 / 15:07

4 answers

5

There are two ways. The first is through the execution of git status, where you will get a message like:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   app/app.iml

no changes added to commit (use "git add" and/or "git commit -a")

In the second line of the return there is something like Your branch is up-to-date with 'origin/master' which tells us that the local arm master is updated relative to the origin/master arm, which is the remote arm. That is, there is nothing to bring from the remote arm ( pull ), nor even send to the remote arm ( push ).

The second way is to run the git push itself and check if something new has been sent through the feedback message. If it is something like Everything up-to-date it means the push has already been performed and there is nothing else to send.

    
23.06.2016 / 15:20
3

git status will tell you if your local branch is delayed or advanced in relation to the source. If you have ahead, then you need to push your updates.

In the example below, I made a local commit that was not pushed to source, so I need to do git push if I want to commit that commit to the source.

D:\mygit\myrepo>git status
On branch carlos_current
Your branch is ahead of 'origin/carlos_current' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

Some notes:

  • You do not always have to git push every commit. A very common workflow in git is you make multiple (small) changes locally and then push all of them at once, possibly by combining the changes in a single
  • You can use a git credential manager to not have to enter the password every time.
23.06.2016 / 15:15
2

I'll leave this here if you want to create a password cache.

  

Why does Git always ask for my password?

If Git prompts you for a username and password every time you try to interact with GitHub, you are probably using the HTTPS URL clone for your repository.

Using a remote URL HTTPS has some advantages: it is easier to configure than SSH, and usually works through strict firewalls and proxies. However, it also prompts you to enter your GitHub credentials each time you do pull or push into a repository.

You can configure Git to store your password for you.

If you would like to configure this, follow the steps below;

Caching your GitHub password in Git

If you are cloning GitHub repositories using HTTPS , you can use a credential helper to tell Git to remember your GitHub username and password each time you talk to GitHub.

If you clone GitHub repositories using SSH, then you authenticate using SSH keys instead of a username and password. To help set up an SSH connection, See Generating an SSH Key .

  

Tip: You need Git 1.7.10 or newer to use the help of   credential.

The credential assistant is included in GitHub Desktop. The application also offers a Git shell, so you will not need to install and configure Git manually. For more information, see "

23.06.2016 / 15:30
0

You can use git log to know the history of commits.

The output will be from the most recent to the oldest commit, along with SHA-1, author name and e-mail, commit date, and message.

Output example

    commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <[email protected]>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <[email protected]>
Date:   Sat Mar 15 16:40:33 2008 -0700

    removed unnecessary test

commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <[email protected]>
Date:   Sat Mar 15 10:31:28 2008 -0700

    first commit

The documentation can be found here

    
23.06.2016 / 15:18