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

Asked

Viewed 1,988 times

5

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

The problem is that sometimes I don’t know if I’ve pulled or not, by doing several things at the same time. Then to find out if I did the git push or not, I execute the git push again. But I’d like a more efficient way to know if I’ve given the git push in the commits I just did, without having to do it all the time (after all, I have to keep typing user and password).

Is there any quicker way of knowing if I’ve ever done the push of the amendments by Git? Something like the git status?

  • You use Git for Windows?

  • 1

    @Dotnet no, use Linux (Ubuntu).

4 answers

5


There are two ways. The first is by running git status, where you’ll 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 return there is something like Your branch is up-to-date with 'origin/master' which tells us that the local arm master is up to date with the arm origin/master, which is the remote arm. That is, there is nothing to bring from the remote arm (pull), not even send to the remote arm (push).

The second way is by executing yourself git push and checking if something new has been sent via the feedback message. If it is something like Everything up-to-date means the push has already been performed and there is nothing more to be sent.

  • The second way is the one I don’t like. Thanks for the "first way"

3

The git status will tell you if his branch site is delayed or advanced from origin. If you have advanced (Ahead), then it means you need to push your updates.

In the example below, I made a local commit that hasn’t been pushed for origin, then it is necessary to do the git push if I want to send this 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 don’t always need to git push every commit. A very common workflow in git is that you make several (small) changes locally and then push them all at once, possibly combining (squash) changes in a single
  • You can use a git Credential manager not have to enter the password every time.

2

I’ll leave this here in case you want to create a password cache.

Why does Git always ask for my password?

If Git asks you for a username and password every time you try to interact with Github, you’re probably using the clone URL HTTPS to your repository.

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

You can configure Git to store your password for you.

If you would like to set this up, 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 are cloning 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 later to use the Git helper credential.

The credential helper is included with Github Desktop. The app also offers a Git shell, so you won’t need to install and configure Git manually. For more information, see " Introduction to Github desktop ."

If you prefer to work with the command line, you can also install a native Git shell, such as Git for Windows . With Git for Windows, running the following on the command line will store your credentials:

git config --global Credential.helper wincred

  • Thanks for the option to save the password, but I won’t use it. I don’t think it’s a good idea in this case. Here at the company we use bitbucket. If I left the company, my password would be easy for someone to take.

  • @Wallacemaxters, really, I’ve used in company like this, but the account I had in git was the company itself there no problem.

  • I had even created a "generic" account, where I could use this user to push them, but then I wouldn’t know who did what. We gave up the idea at the end :D

0

You can use git log for commit history.

Output will be from the most recent commit to the oldest, along with SHA-1, author’s name and email, 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

Documentation can be found here

  • 1

    But you agree with me that I can commit without pulling and even then git log will work, it’s not ?

  • 1

    @Wallacemaxters is right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.